import random
import time


money = 5000  # 账户金额
a = ['水果', '零食', '衣服', '饮料', '家具', '电子产品']   # 商城物品名称
b = [20, 30, 50, 10, 2000, 300]  # 商品价格
c = list()  # 购物车

flag = True  # 标志位
s_yhq = ['水果', '零食', '衣服', '饮料', '家具', '电子产品', '电子产品', '衣服', '衣服', '饮料']
yhq = ['6', '8', '7', '8', '7', '9', '6', '8', '7', '7']
user_yhq = random.randint(0, len(yhq)-1)
zk = int(yhq[user_yhq]) * 0.1
print("你抽中的是:" + str(s_yhq[user_yhq]) + "折扣为" + str(yhq[user_yhq]) + "折")
ksy = 1
e = 1
count = 0
num2 = 0
while e > 0:
    for i in range(999):
        s = input("请你输入想要的商品:" + "\n")
        for j in range(len(a)):
            if s == a[j] and s == s_yhq[user_yhq]:
                count = j
                ksy = ksy*zk
        if s in a:
            if b[count] <= money:
                print(str(a[count]) + "单价为" + str(b[count]))
                g = input("您是否要将此商品添加购物车,输入1添加,输入2不添加" + "\n")
                if g == "1":
                    num = int(input("请输入你想购买此商品的数量:"))
                    num2 = num
                    c.append(a[count])
                    if num == 1:
                        money -= b[count] * ksy
                    elif num > 1:
                        money = money - b[count] * ksy
                        money -= b[count] * (num-1)
                    print("恭喜，购买成功！您的卡余额还剩:"+str(money))
                    s1 = input("输入Q或者q,退出系统:" + "\n")
                    if s1 == "Q" or s1 == "q":
                        flag = False
                        print("系统退出")
                        break
                    else:
                        print("继续购物")
                else:
                    break
            else:
                print("穷鬼，钱不够！请到其他超市购买！")
                flag = False
                break
        else:
            print("没有这个商品，别瞎弄！")
            print("继续购物")
    if not flag:
        break  # 退出外层循环

hf = 0
print("\n您的购物车商品如下:")
for k in range(len(c)):
    for j in range(len(a)):
        if c[k] == a[j]:
            count = j
    if num2 == 1:
        hf = b[count] * ksy
    elif num2 > 1:
        hf = b[count] * ksy + b[count] * (num2 - 1)
    print(str(c[k]) + " 花费为 " + str(int(hf)) + " 购买数量:" + str(num2) + "\n")



timestamp = time.time()
# 转换为本地时间并打印
local_time = time.localtime(timestamp)
# 格式化打印
formatted_time = time.strftime("%Y年%m月%d日 %H时%M分%S秒", local_time)
print("购物时间：", formatted_time)
print("总共花费"+str(int(5000 - money)))
print("您的账户剩余金额为:" + str(money))




